//
//  XFBaseTableViewController.m
//  OrderFood
//
//  Created by xiaofang wang on 2018/10/24.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//

#import "XFBaseTableViewController.h"

@interface XFBaseTableViewController ()
@property (nonatomic, strong,readonly) MJRefreshAutoNormalFooter* ls_footer;
@end

@implementation XFBaseTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)loadTableViewWithFrame:(CGRect)frame tableViewStyle:(UITableViewStyle)style refreshStyle:(LSRefreshType)refreshtype{
    _mytableview = [[UITableView alloc] initWithFrame:frame style:style];
    _mytableview.backgroundColor = BACKGROUNDCOLOR;
    _mytableview.rowHeight = UITableViewAutomaticDimension;
    _mytableview.separatorStyle  = UITableViewCellSeparatorStyleNone;
    _mytableview.estimatedRowHeight = 100;
    [self.view addSubview:_mytableview];
    switch (refreshtype) {
            case LSRefreshTypeDefault:{
                //
                [self loadRefreshViewJustHeader:NO];
                break;
            }
            case LSRefreshTypeJustHeader:{
                //
                [self loadRefreshViewJustHeader:YES];
                break;
            }
            case LSRefreshTypeJustFooter:{
                //
                [self loadRefreshViewJustFooter];
                break;
            }
        default:
            break;
    }
}

#pragma mark - 刷新

- (void)loadRefreshViewJustHeader:(BOOL)justheader{
    //
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestNewData)];
    if (_mytableview) {_mytableview.mj_header = header;}
    
    if (!justheader) {
        _ls_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestMoreData)];
//         [_ls_footer setTitle:@"无更多内容" forState:MJRefreshStateNoMoreData];
        if (_mytableview) {_mytableview.mj_footer = _ls_footer;}
        
    }
    
}

- (void)loadRefreshViewJustFooter{
    _ls_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(requestMoreData)];
//     [_ls_footer setTitle:@"无更多内容" forState:MJRefreshStateNoMoreData];
    if (_mytableview) {_mytableview.mj_footer = _ls_footer;}
    
}
- (void)requestNewData{
    
}
- (void)requestMoreData{
    
}

- (void)ls_headerBeginRefreshing{
    [_mytableview.mj_header beginRefreshing];
}
- (void)ls_headerEndRefreshing{
    [_mytableview.mj_header endRefreshing];
}

- (void)ls_footerEndRefreshing{
    [_mytableview.mj_footer endRefreshing];
}
#pragma mark-分割线补全
- (void)viewDidLayoutSubviews {
    
    if ([self.mytableview respondsToSelector:@selector(setLayoutMargins:)]) {
        
        self.mytableview.layoutMargins = UIEdgeInsetsZero;
    }
    if ([self.mytableview respondsToSelector:@selector(setSeparatorInset:)]) {
        
        self.mytableview.separatorInset = UIEdgeInsetsZero;
    }
}
@end
